// MainFrm.h : interface of the CMainFrame class
//
/////////////////////////////////////////////////////////////////////////////

#if !defined(AFX_MAINFRM_H__3A8B2CF3_8823_4179_A5C8_6B60861E77CA__INCLUDED_)
#define AFX_MAINFRM_H__3A8B2CF3_8823_4179_A5C8_6B60861E77CA__INCLUDED_

#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000

#include "TCToolBar.h"

// Default maximal frame size
#define VP_ROI_MAX_WIDTH	1280
#define VP_ROI_MAX_HEIGHT	500

// a point with double percission
typedef struct {
	double x,y;
} dPoint;

// parameters returned to the view calss for showing them on screen
typedef struct {
	bool bPoleTouch;
	bool bSaveStopped;
	bool bError;
	HANDLE hAnalyzeStopped;
	unsigned long lFrameNumber;
	double MedianArray[1024]; // 2^10, for speed as this array is pushed to FFT analysis
	double AngleArray[1024]; // 2^10, for speed as this array is pushed to FFT analysis
	double FFTWAmplitude[1024];
	double FFTWFrequency[1024];
	double dFFTWBandPassSNR;
} Result_Params;

typedef struct {
	byte				*Motion_Threshold;			// Minimum gray level to be considerd motion
	double				*Pole_Threshold;			// A precentage of white area from the vp area. if the white area of a frame wthin the VP area is larger then it considered a touch in the pole. 
	long				*Median_Threshold;			// Minimum number of motion pixels to be considered as motion
	bool				*ComputeFFTW;				// Compute real-time FFT
	bool				*EnableRealTimeTracking;	// Compute real-time motion
	//CRect				*VP;						// Contain the current active pole (pointer)
	int					*VPIndx;					// Current selected virtual object (pointer)
	CRect				*AllVP;						// Array of all poles locations (pointer)
	CRgn				*MotionMask;				// Motion mask, pointer
	CRITICAL_SECTION	*LockRawVideo;				// a pointer to the Critical Sections array that locks up the raw video data
	CRITICAL_SECTION	*LockAnalyzedVideo;			// a pointer to the Critical Sections array that locks up the analyzed video data
	LPCTSTR				LogPath;					// Path where log files are saved
	LPCTSTR				CameraMode;					// Camera mode (e.g. Free-run, ExSync etc)
	LPCTSTR				CameraControlLine;			// Camera control line (ExSync)
	LPCTSTR				CameraTriggerLine;			// Camera trigger IN line
	LPCTSTR				CameraTriggerOutLine;		// Camera trigger OUT line
	LPCTSTR				TrackingOutputCh;			// Tracking output channels
	LPCTSTR				EventTriggerCh;				// event trigger channel
	LPCTSTR				EventTriggerDev;			// event trigger device
	LPCTSTR				IndicatorTriggerINCh;		// indicator trigger input channel
	BOOL				SaveLog;					// A flag for saving the log file
	LPCTSTR				VideoPath;					// the path to save the Video file to
	BOOL				AnalyzeVideo;				// A flag for analyzing the video or just saving it
	BOOL				TriggerOverlays;			// A flag for including trigger overlay squares in saved frames
	bool				*DetectMotionInObjects;		// Flag to detection motion only inside objects
	bool				*DetectMotion;				// Flag to enable motion detection
	dPoint				ConversionFactor;			// A conversation factor to convert pixels to mm. 0 if no need to convert.
	double				Angle;						// The angle of the medial line
	unsigned int		FPS;						// the frame rate in frames per second		
	double				FrameExposure;				// the frame rate in frames per second		
	POINT				RawBufferSize;				// x - the amount of memory (in fames) to allocate for saving the Raw video. y - size in bytes of each frame
	POINT				AnalyzedBufferSize;			// x - the amount of memory (in fames) to allocate for saving the Analyzed video. y - size in bytes of each frame
	long				FrameLimit;					// maximum number of frames in the saved video
	bool				*EnableFrequencyTrigger;	// enable frequency trigger (from real-time FFT)
	bool				*EnableProximityTrigger;	// enable proximity/contact trigger
	long				*FreqSNRThreshold;			// Frequency SNR threshold (from FFT)
	long				*FrequencyBandpassLow;		// Frequency bandpass LOW
	long				*FrequencyBandpassHigh;		// Frequency bandpass HIGH
} Analyze_Params;

typedef struct {
	long intSettings[19];
	// 0  - The Number of the selected pole from the poles list [#]
	// 1  - Total Number poles on the pole list [#]
	// 2  - ROI Width [pix]
	// 3  - ROI Height [pix]
	// 4  - ROI X Position [pix]
	// 5  - ROI Y Position [pix]
	// 6  - Motion Threshold [pix]
	// 7  - Pole Threshold [%]
	// 8  - Median Threshold [%]
	// 9  - FPS [#/sec]
	// 10 - Video Buffer Size [MB]
	// 11 - Video Buffer Size [Frames]
	// 12 - Boxcar Window Size [#]
	// 13 - Median amplitude threshold
	// 14 - Pole contacts
	// 15 - Frame exposure time
	// 16 - Frequency SNR threshold
	// 17 - Frequency bandpass LOW
	// 18 - Frequency bandpass HIGH
	
	bool boolSettings[21];
	// 0  - Mesurement units are mm 
	// 1  - Select pole by external program
	// 2  - Save Log file
	// 3  - Don't Analyze Pole
	// 4  - View the Tool bar
	// 5  - View the status bar
	// 6  - View Only the ROI
	// 7  - View the Pole Location
	// 8  - View analyzed Video
	// 9  - View Captured Video
	// 10 - View Frame numbers
	// 11 - View Retraction / Protraction state
	// 12 - Keep Aspect ratio
	// 13 - Check median position
	// 14 - View trigger indicator overlays
	// 15 - View real-time FFT
	// 16 - Enable frequency trigger
	// 17 - Enable proximity/contact trigger
	// 18 - Enable real-time motion tracking
	// 19 - Enable motion detection only inside virtual objects
	// 20 - Enable motion detection (false = simple thresholding)

	CString Paths[12];
	// 0  - Log file path
	// 1  - Video file path
	// 2  - Settings file path
	// 3  - Camera mode (not a path, but placed here since its stored as a CString)
	// 4  - Camera control ExSync line
	// 5  - Camera trigger IN line
	// 6  - Camera trigger OUT line
	// 7  - Tracking output channel 1
	// 8  - Tracking output channel 1
	// 9  - Event trigger channel
	// 10 - Event trigger device
	// 11 - Indicator trigger input channel

	CString *PoleList;	// the list of poles and their parameters

	dPoint	ConversionFactor;	// A conversation factor to convert pixels to mm. 0 if no need to convert
	double	MedLineAngle;		// the angle of the Medial Line

	HANDLE Operations[5];
	// 0  - Snap
	// 1  - Start Analyze
	// 2  - Start Saving Video
	// 3  - Stop Analyze
	// 4  - Close Video

} Settings_Params;

const double PI=3.14159265358979323846;
const UINT RingBufferSize = 5; // was 5 

class CMainFrame : public CFrameWnd
{
	
protected: // create from serialization only
	CMainFrame();
	DECLARE_DYNCREATE(CMainFrame)

// Attributes
public:

// Operations
public:

// Overrides
	// ClassWizard generated virtual function overrides
	//{{AFX_VIRTUAL(CMainFrame)
	virtual BOOL PreCreateWindow(CREATESTRUCT& cs);
	//}}AFX_VIRTUAL

// Implementation
public:

	virtual ~CMainFrame();
#ifdef _DEBUG
	virtual void AssertValid() const;
	virtual void Dump(CDumpContext& dc) const;
#endif

protected:  
	// control bar embedded members
	CStatusBar		m_wndStatusBar;
	CTCToolBar		m_wndToolBar;

// Generated message map functions
protected:
	//{{AFX_MSG(CMainFrame)
	afx_msg int OnCreate(LPCREATESTRUCT lpCreateStruct);
	//}}AFX_MSG
	DECLARE_MESSAGE_MAP()

public:

};

/////////////////////////////////////////////////////////////////////////////

//{{AFX_INSERT_LOCATION}}
// Microsoft Visual C++ will insert additional declarations immediately before the previous line.

#endif // !defined(AFX_MAINFRM_H__3A8B2CF3_8823_4179_A5C8_6B60861E77CA__INCLUDED_)
